package com.startprowry631;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.startprowry631.bean.WeatherInfo;
import com.startprowry631.listener.WeatherListener;
import com.startprowry631.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements WeatherListener, View.OnClickListener{
    private EditText cityNOInput;
    private TextView tv_cityname;
    private Button btn_find1;
    private Button btn_find2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
private  void  init(){
    cityNOInput=(EditText)findViewById(R.id.et_cityno);
    btn_find1=(Button)findViewById(R.id.button1);
    btn_find2=(Button)findViewById(R.id.button2);
    tv_cityname=(TextView)findViewById(R.id.tv_cityname);
    btn_find1.setOnClickListener(this);
}
    @Override
    public void onResponse(WeatherInfo weather) {
if(weather!=null){
    tv_cityname.setText(weather.getCity());
}
else{
    tv_cityname.setText("未知");
}
    }

    @Override
    public void onFail(String msg) {
tv_cityname.setText("失败");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button1:
                WeatherModel weatherModel=new WeatherModel();
                weatherModel.getWeather(cityNOInput.getText().toString(),this);
                break;
            case R.id.button2:
                break;
            default:
                break;
        }
    }
}
